package com.zr.rocketmq.consumer;

import com.zr.rocketmq.entity.Order;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
// 消费普通订单消息
@RocketMQMessageListener(topic = "order_topic", consumerGroup = "order_consumer_group", selectorExpression = "create")
public class OrderMessageConsumer implements RocketMQListener<Order> {

    @Override
    public void onMessage(Order order) {
        log.info("收到订单消息，开始处理...");
        log.info("订单ID: {}", order.getOrderId());
        log.info("用户ID: {}", order.getUserId());
        log.info("商品ID: {}", order.getProductId());
        log.info("订单金额: {}", order.getAmount());
        
        // 这里可以添加订单处理逻辑，如库存扣减、物流创建等
        log.info("订单处理完成，状态更新为SUCCESS");
    }
}
